<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAgentRewardsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('agent_rewards', function (Blueprint $table) {
            $table->id();
            $table->bigInteger('agent_id')->index()->comment('代理商 ID');
            $table->bigInteger('reward_setting_id')->index()->comment('奖励设置 ID');
            $table->text('reward_setting_snapshot')->nullable()->comment('奖励设置快照');

            $table->tinyInteger('type')->comment('类型(由 agent_reward_rule_settings 表 type 决定); 1:充值奖励 2:每日下单奖励 3:每月下单奖励');
            $table->unsignedBigInteger('threshold_amount')->comment('门槛金额 单位分');
            $table->unsignedBigInteger('reward')->comment('奖励金额 单位分');
            $table->date('award_date')->index()->comment('获奖日期');

            $table->bigInteger('source_id')->default(0)->comment('相关对象(订单) ID');
            $table->char('source_type', 64)->default('')->comment('相关对象 Model');
            $table->index(['source_id', 'source_type']);

            $table->tinyInteger('status')->default(1)->comment('状态; 1:待审核 2:已通过 3:已驳回 4:已撤销 5:已追回');
            $table->string('remark')->default('')->comment('备注');
            $table->bigInteger('operator_id')->default(0)->comment('操作员 ID');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('agent_rewards');
    }
}
